var Login = function(){
	var userId;
	var userPassword;
	var submitButton;
	var resetButton;
	return{
		validate:function(){
			document.getElementById("errorMsg").innerHTML = "";
			var userId = document.getElementById("userId").value;
			if(userId == null && userId.replace(/(^\s*)|(\s*$)/g, "") == ""){
				document.getElementById("errorMsg").innerHTML = "用户编号不能为空";
				return false;
			}else{
				document.getElementById("errorMsg").innerHTML = "";
			}
			var userPassWd = document.getElementById("userPassWd").value;
			if(userPassWd == null || userPassWd.replace(/(^\s*)|(\s*$)/g, "") == ""){
				document.getElementById("errorMsg").innerHTML = "用户密码不能为空";
				return false;
			}else{
				document.getElementById("errorMsg").innerHTML = "";
			}
			return true;
		},
		submitForm:function(){
			if(Login.validate() == true){
				document.getElementById("errorMsg").innerHTML = "";
				$.ajax({
					url:'/my/login.do',
					type:'post',
					timeout:15*1000,
					data:{
						userId:document.getElementById("userId").value,
						userPassWd:document.getElementById("userPassWd").value,
						imgcode:document.getElementById("valicode").value
					},
					success:function(json){
						if(json.success){
							window.location.href="/"+json.message;
								return false;
						}else{
							document.getElementById("errorMsg").innerHTML = json.message;
							document.getElementById("valicode").value = "";
							Login.reloadPic();
						}
					},
					complete:function(request,status){
						if(status=="timeout"){
							document.getElementById("errorMsg").innerHTML = "请求超时";
							return false;
						}
					}
				});
			}
			
		},
		resetForm:function(){
			document.getElementById("userId").value = "";
			document.getElementById("userPassWd").value = "";
			document.getElementById("errorMsg").innerHTML = "";
			document.getElementById("valicode").value = "";
		},
		reloadPic:function (){
			var img=document.getElementById("codeImg");
			img.src = "/my/img/getvercode.do?rnd=" + Math.random(); 
		}
	}
}();
